/*
 * @Author: yaoling 1871883713@qq.com
 * @Date: 2022-10-17 10:24:39
 * @LastEditors: yaoling 1871883713@qq.com
 * @LastEditTime: 2022-12-26 14:17:24
 * @FilePath: \company-world\src\apis\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 可以通过：Request.get<DataType>({url:/home})来使用
import HYRequest from './request/request'
import { getToken } from '@/utils/token-cache'

const API_BASE_URL = 'http://localhost:3008'
const TIME_OUT = 10000

// 实例化一个HYRequest对象
const Request = new HYRequest({
  baseURL: API_BASE_URL,
  timeout: TIME_OUT,

  // 请求拦截器
  interceptorHooks: {
    // 请求成功
    requestInterceptor: (config: any) => {
      // 类型不确定

      const token = getToken()
      if (token) {
        config.headers.Authorization = `Bearer ${token}`
        config.headers.token = token
      }
      // config.headers.bimcctoken = token
      return config
    },
    // 请求失败
    requestInterceptorCatch: (err) => {
      return err
    },

    // 响应成功
    responseInterceptor: (res) => {
      return res
    },
    // 响应失败
    responseInterceptorCatch: (err) => {
      return err
    }
  }
})

export default Request
